package com.leyou.item.mapper;

import com.leyou.item.pojo.Brand;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * 通用mapper简化开发，实现增删改查
 */
public interface BrandMapper extends Mapper<Brand>{

    /**
     * 新增商品分类和品牌中间表数据
     * @param cid 商品分类id
     * @param bid 品牌id
     * @return
     */
    @Insert("INSERT INTO tb_category_brand (category_id, brand_id) VALUES (#{cid},#{bid})")
    int insertCategoryBrand(@Param("cid") Long cid, @Param("bid") Long bid);


    /**
     * 根据cid查询品牌列表
     *
     * 内连接查询
     *
     * @param cid
     * @return
     */
    @Select("SELECT b.id,b.name,b.letter,b.image\n" +
            "FROM tb_brand b\n" +
            "INNER JOIN tb_category_brand cb ON b.id = cb.brand_id\n" +
            "WHERE cb.category_id =#{cid}")
    List<Brand> queryByCategoryId(@Param("cid") Long cid);
}
